<?php
namespace app\admin\controller;
use think\view;
use think\Db;
use think\Session;
use Qiniu\Auth as Auth;
class tag extends CommonController
{
    //标签管理
    public function index()
    {
        return $this->fetch();
    }

    //获取标签接口
     public function get_tags(){
         $list = DB::name('newtag')
             ->select();
         if($list){
             $data['code'] = '0';
             $data['msg'] = '';
             $data['count'] = count($list);
             $data['data'] = $list;
         }else{
             $data['code'] = '0';
             $data['msg'] = '暂无数据';
             $data['count'] = 0;
             $data['data'] = '';
         }

         exit(json_encode($data));
     }

     //添加下级标签名称
    public  function add(){
        if($_GET){
            $map['id']  = $_GET['id'];
            $list = Db::name('newtag')->where($map)->find();

            $this->assign('list',$list);
        }
        return $this->fetch();
    }

    public function up_add(){


        $data['authorityName'] = $_POST['authorityName'];
        $data['parentId'] = $_POST['orderNumber'];


        $add = Db::name('newtag')->insert($data);

        $Id = Db::name('newtag')->getLastInsID();
        $data1['authorityId'] = $Id;
        $data1['orderNumber'] = $Id;
        $data1['id'] = $Id;
        $res = Db::name('newtag')->update($data1);
        if($res){
            return show(1,'添加成功');
        }else{
            return show(0,'添加失败，请重试');
        }
    }


    //删除标签
    public function del(){
        if($_POST){
            $map['id'] = $_POST['id'];
            $res = Db::name('newtag')->where($map)->delete();
            if($res){
                return show(1,'删除成功');
            }else{
                return show(0,'删除失败');
            }
        }
    }

    //修改标签
    public function edit(){
        if($_GET){
            $map['id']  = $_GET['id'];
            $list = Db::name('newtag')->where($map)->find();

            $this->assign('list',$list);
        }
        return $this->fetch();
    }

    public function up_edit(){
        $data['authorityName'] = $_POST['authorityName'];
        $data['id'] = $_POST['id'];
        $res = Db::name('newtag')->update($data);
        if($res){
            return show(1,'修改成功');
        }else{
            return show(0,'修改失败，请重试');
        }
    }

    //获取对应技术
    public function get_developer(){
        if($_POST){
         $data = $_POST['data'];
         $res = db::name('developer')
             ->  where('tags','like', "%".$data."%")
             ->select();
          for($i=0;$i<count($res);$i++){
              $list[$i]['name'] = $res[$i]['name'];
              $list[$i]['phone'] = $res[$i]['phone'];
          }
           exit(json_encode($list));

        }
    }

}
